package com.sc.server.system.common.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public class UserUtils {
    /**
     * 获取登录用户信息
     * @return
     */
    public static String getUser(){
        String username=null;
        username = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                    .getHeader(AuthConst.AUTH_USER);

        return StringUtils.isBlank(username)?"admin":username;
    }
    public static Long getUserId() {
        String user = null;
        try {
            user = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                    .getHeader(AuthConst.Auth_Id);
            return StringUtils.isBlank(user) ? 32 : Long.parseLong(user);
        } catch (Exception e) {
            return 0L;
        }
    }
    public static String getTenantId() {
        String tenantId = null;
        try {
            tenantId = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                    .getHeader("tenantId");
            return StringUtils.isBlank(tenantId) ? "0" : tenantId;
        } catch (Exception e) {
            return "0";
        }
    }
    public static String getUserGroupId(){
        String groupid=null;
        groupid = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()
                .getHeader(AuthConst.GROUP_ID);

        return groupid;
    }

}
